﻿@model Wei.Model.User_Model
@{
    ViewBag.Title = "资料设置";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
<div class="layui-row">
    <div class="layui-col-md2">
        @Html.Partial("User_Menu_Partial","user_info")
    </div>

    <div class="layui-col-md10" style="min-height:680px;background-color:#ffffff;">
        <div class="layui-row">
            <form class="layui-form layui-form-pane" action="" style="margin: 15px;">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-inline">
                            <input type="text" name="u_phone" id="u_phone" value="@Model.u_phone" autocomplete="off" maxlength="11" placeholder="请输入电话" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">年龄</label>
                        <div class="layui-input-inline">
                            <input type="number" name="u_age" id="u_age" value="@Model.u_age" lay-verify="required" placeholder="请输入年龄" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="u_name" id="u_name" value="@Model.u_name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item" style="width: 300px;" pane="">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-inline">
                            @if (Model.u_sex == true)
            {
                <input type="radio" name="u_sex" value="true" title="男" checked="">
                <input type="radio" name="u_sex" value="false" title="女">
}
else
{
                <input type="radio" name="u_sex" value="true" title="男">
                <input type="radio" name="u_sex" value="false" title="女" checked="">
}
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="btn_img">点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" src="@Model.u_img" width="200" height="150" id="c_cover_img">
                                <p id="demoText"></p>
                                <input type="hidden" id="svaePath" value="@Model.u_img" />
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-col-md12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">地址</label>
                        <div class="layui-input-inline">
                            <select name="quiz1">
                                <option value="">请选择省</option>
                                <option value="浙江" selected="">浙江省</option>
                                <option value="你的工号">江西省</option>
                                <option value="你最喜欢的老师">福建省</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="quiz2">
                                <option value="">请选择市</option>
                                <option value="杭州">杭州</option>
                                <option value="宁波" disabled="">宁波</option>
                                <option value="温州">温州</option>
                                <option value="温州">台州</option>
                                <option value="温州">绍兴</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="quiz3">
                                <option value="">请选择县/区</option>
                                <option value="西湖区">西湖区</option>
                                <option value="余杭区">余杭区</option>
                                <option value="拱墅区">临安市</option>
                            </select>
                        </div>
                    </div>


                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">个性签名</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" maxlength="250" id="u_style_sign" class="layui-textarea">@Model.u_style_sign</textarea>
                        </div>
                    </div>
                </div>



                
                <div class="layui-form-item">
                    <button class="layui-btn" type="button" onclick="Edit_User()" lay-submit="" lay-filter="demo2">保存</button>
                </div>
            </form>

        </div>
    </div>
</div>
<br />
<script>
    var form = layui.form
        , upload = layui.upload;
    //普通图片上传
    var uploadInst = upload.render({
        elem: '#btn_img'
        , exts: 'jpg|png|gif|bmp|jpeg'
        , size:500
        , url: '/User/Uploag_img?u_id='+'@Model.u_id'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#c_cover_img').attr('src', result); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code === "1") {
                $("#svaePath").val(res.svaePath);
                $("#top_user_img").attr('src', res.svaePath + '?t=' + Math.random());
                return layer.msg('上传成功');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            //var demoText = $('#demoText');
            //demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            //demoText.find('.demo-reload').on('click', function () {
            //    uploadInst.upload();
            //});
        }
    });


    function Edit_User() {
        var u_phone = $("#u_phone").val();
        var u_name = $("#u_name").val();
        var u_age = $("#u_age").val();
        var u_sex = $("input[name='u_sex']:checked").val();
        var u_style_sign = $("#u_style_sign").val();
        if (u_phone == "") {
            layer.alert("手机号不能为空");
            return;
        }
        if (u_phone.indexOf('script')!=-1) {
            layer.alert("手机号有问题");
            return;
        }
        if (u_name == "") {
            layer.alert("手昵称不能为空");
            return;
        }
        if (u_name.indexOf('script') != -1) {
            layer.alert("昵称有问题");
            return;
        }
        if (u_style_sign.indexOf('script') != -1) {
            layer.alert("个性签名有问题有问题");
            return;
        }
        $.post_str("/User/Edit_User", { u_id: '@Model.u_id', u_phone: u_phone, u_name: u_name, u_age: u_age, u_sex: u_sex, u_style_sign: u_style_sign, user_img: $("#svaePath").val()}, function (data) {
            if (data == "1") {
                layer.alert("保存成功");
            } else {
                layer.alert(data);
            }

        });
    }
</script>


